package com.briup.day15;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author lining
 * @date 2024/1/25 9:19
 */
public class TestTreeMap {
    public static void main(String[] args) {
        //将数据以key的排序方式进行存储 学生和老师对应关系 排序规则：学生学号
        Map<Student,Teacher> map = new TreeMap<>(new Comparator<Student>() {
            public int compare(Student o1, Student o2) {
                return o1.getId() - o2.getId();
            }
        });
        //提供比较器或者key自然排序规则
        map.put(new Student(1),new Teacher(10));
        map.put(new Student(3),new Teacher(8));
        map.put(new Student(5),new Teacher(8));
        map.put(new Student(2),new Teacher(10));
        map.put(new Student(1),null);//key排序 value
        System.out.println(map);//

    }
}
